package com.speily.current;

import java.util.concurrent.TimeUnit;

/**
 * @Auther: SPL
 * @Date: 2019-08-05 13:40
 * @Description: - 线程响应中断
 */
public class InterruptedTest implements Runnable{
    @Override
    public void run() {
        while (!Thread.currentThread().isInterrupted()){
            System.out.println(Thread.currentThread().getName() + "运行中。。");
        }

        System.out.println(Thread.currentThread().getName() + "收到中断通知，退出！");
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new InterruptedTest(), "thread A");
        thread.start();

        System.out.println("main 线程正在运行") ;

        TimeUnit.MILLISECONDS.sleep(3) ;
        thread.interrupt();//更改线程状态，通知thread A

        TimeUnit.MILLISECONDS.sleep(10) ;
        System.out.println("main 线程正在运行，主线程该干啥干啥...") ;
    }

}
